package ng.map.elements.objects;

import java.awt.Graphics2D;
import java.io.IOException;

import ng.graphics.Animation;
import ng.graphics.FrameBuffer;
import ng.lib.Vector2D;
import ng.map.MapObject;
import ng.map.MapObjectDynamic;
import ng.map.collision.CollisionBound;
import ng.map.collision.CollisionCircle;

public class Wabber extends MapObjectDynamic {
	private static FrameBuffer frames;
	private static CollisionBound collisionBoundHolder = new CollisionCircle(new Vector2D(17,44),5);
	

	static {
		try {
			String[] p = new String[30];
			for(int i = 0;i < p.length; i++){
				p[i] = "data/textures/projectiles/wabber/00"+(i+30)+".png";
			}
			frames = new FrameBuffer(p);
		} catch (IOException e) {
			System.err.println("An image isn't at the right place");
			e.printStackTrace();
		}
	}

	private static final int LIFETIME = 200; //Lebensdauer in ticks.
	
	
	private int life = 0;
	
	public Wabber(Vector2D p) {
		super(collisionBoundHolder);
		this.animation = new Animation(frames, 1);
		this.position = p;
		this.mass = 0;
	}
	
	@Override
	public void collides(MapObject mo) {
		super.collides(mo);
		this.mapCallback.kill(this);
	}
	
	@Override
	public void tick() {
		super.tick();	
		
		this.life++;
		if(this.life >= Wabber.LIFETIME)
			this.mapCallback.kill(this);
		
		this.setAngle(Math.atan(this.speed.x/this.speed.y));
		this.angle += Math.PI/2;
		
	}

	@Override
	public void draw(Graphics2D g2) {
		super.draw(g2);
	}

}
